<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>APP版本管理</title>
	<jsp:include page="../../import.jsp" flush="true" />
	<script src="<%=path %>/resource/lib/ueditor/ueditor.config.js" charset="utf-8" type="text/javascript"></script>
	<script src="<%=path %>/resource/lib/ueditor/ueditor.all.min.js" charset="utf-8" type="text/javascript"></script>
	<!--建议手动加载语言，避免在IE下有时因为加载语言失败导致编辑器加载失败-->
	<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	<script src="<%=path %>/resource/lib/ueditor/lang/zh-cn/zh-cn.js" charset="utf-8" type="text/javascript"></script>
	<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
	<script type="text/javascript">
		$(function () {
			initForm();
			initUedit();
			saveEvent();
		});

		//初始化表单
		function initForm(){
			$("#formSet1").ligerForm({
				validate: true
			});
		}
		function initUedit(){
			var ue = UE.getEditor('editor');
			ue.addListener("ready", function () {
				// editor准备好之后才可以使用
				ue.setContent($("#uecontent").html());
			});
		}
		//保存事件
		function saveEvent(){
			$("#saveBtn1").click(function(event) {
				var form = liger.get("formSet1");
				if (!form.valid()) {
					top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
					return false; //验证不通过，不执行以下代码
				}
				var verDscr=UE.getEditor('editor').getContent();
				var data = form.getData();
				data["verDscr"] = verDscr;
				var url = '<%=path%>/upgrade/sysAppVerCfg/modifySysAppVerCfg.do';
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType:'json',
					data:data,
					url: url,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							var callback=GET_W2Wcallback();
							callback();
							Remove_navTab ();
						}else{
							top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					}
				});
			});
		}

		function getVerId(){
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{},
				url: '<%=path%>/upgrade/sysAppVerCfg/getVerId.do',
				success:function(msg){
					if(msg.success == 1){
						$("#verId").val(msg.data);
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		}
	</script>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<form id="formSet1">
		<table class="layout2col1">
			<tbody>
			<tr>
				<td valign="top">
					<div class="fieldset1 tabel_col clearFix">
						<div class="fieldBox col_50">
							<div class="label">系统</div>
							<div class="field">
								<select name="sysCd" id="sysCd" disabled="disabled"
										validate="{required:true,select:true}">
									<option value=" " >请选择</option>
									<c:forEach items="${syscdlist }" var="syscdop">
										<option value="${syscdop.key }" <c:if test="${sysappvercfg.sysCd == syscdop.key}">selected</c:if>>${syscdop.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">APP类型</div>
							<div class="field">
								<select name="opTypCd" id="opTypCd" validate="{required:true,select:true}">
									<option value=" " >请选择</option>
									<c:forEach items="${optypcdlist }" var="optypcdop">
										<option value="${optypcdop.key }" <c:if test="${sysappvercfg.opTypCd == optypcdop.key}">selected</c:if>>${optypcdop.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">升级版本号</div>
							<div class="field">
								<input name="verId" id="verId" type="text" ligerui="digits:true" class="ui-textbox" value="${sysappvercfg.verId}" validate="{required:true}">
								<span id="getBtn" class="sq-button sq-button-hasicon" onclick="getVerId()"><i class="sqBtnIco_2"></i>获取升级版本号</span>
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">显示版本号</div>
							<div class="field">
								<input name="verNo" id="verNo" type="text" class="ui-textbox" value="${sysappvercfg.verNo}" validate="{required:true}">
							</div>
						</div>
						<div class="fieldBox col_50">
							<div class="label">发布时间</div>
							<div class="field">
								<input name="relDt" id="relDt" type="text" class="ui-textbox" disabled="disabled" value="${sysappvercfg.relDtStr}" validate="{required:true}">
							</div>
						</div>

						<div class="fieldBox col_50">
							<div class="label">上传APP</div>
							<div class="field">
								<input type="file" id="fileUpload" name="fileUpload" >
								<span class="sq-button sq-button-hasicon" id="btnUpload"><i class="sqBtnIco_9"></i>上传</span>
							</div>
						</div>

						<div class="fieldBox col_100_auto">
							<div class="label">下载地址</div>
							<div class="field">
								<input name="instFileUrl" id="instFileUrl" type="text" class="ui-textbox" ligerui="width:700" value="${sysappvercfg.instFileUrl}" validate="{required:true}">
							</div>
						</div>

						<div class="fieldBox col_100_auto">
							<div class="label">更新内容</div>
							<div class="field" style="width: 100%; box-sizing: border-box;">
								<script id="editor" type="text/plain" style="width:99%; height:280px;"></script>
							</div>
						</div>


						<div class="fieldBox col_100_auto">
							<div class="label">是否强制更新</div>
							<div class="field">
								<c:choose>
									<c:when test="${not empty sysappvercfg && sysappvercfg.isForceUpdate==1}">
										是<input type="radio" name="isForceUpdate" value="1" checked>&nbsp;&nbsp;
										否<input type="radio" name="isForceUpdate" value="0">
									</c:when>
									<c:otherwise>
										是<input type="radio" name="isForceUpdate" value="1" >&nbsp;&nbsp;
										否<input type="radio" name="isForceUpdate" value="0" checked>
									</c:otherwise>
								</c:choose>
							</div>
						</div>
						<div class="fieldBox col_100_auto" id="divVerType">
							<div class="label">APP类型</div>
							<div class="field">
								<select name="verType" id="verType"   data-value="${sysappvercfg.verType}" >
									<option value=" " >请选择</option>
									<option value="1">全部</option>
									<option value="2">单板</option>
									<option value="3">区间</option>
								</select>
							</div>
						</div>
						<div class="fieldBox col_100_auto" id="divVerRule">
							<div class="label">版本号</div>
							<div class="field">
								<input name="verRule" id="verRule" type="text" class="ui-textbox" ligerui="width:700" value="${sysappvercfg.verRule}">
							</div>
						</div>
					</div>

					<div id="btnsBox" class="btnsBox">
						<input name="sysappId" id="sysappId" type="text" style="display: none;" value="${sysappvercfg.id}"/>
						<span id="saveBtn1" class="sq-button sq-button-round">保存</span>
						<input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
					</div>
				</td>
			</tr>
			</tbody>
		</table>
	</form>
</div>
<div class="clearLine"></div>
<div id="uecontent" style="display:none">${sysappvercfg.verDscr}</div>
</body>
<script type="text/javascript">
	//上传回调方法必须写在上传插件之后
	var serverpath = '${serverpath}';
	function uploadCallback(_data){
		if(_data&&_data.length>0) {
			$("#instFileUrl").val(_data);
		}
	}
</script>
<script type="text/javascript">
	$(function () {
		$("#btnUpload").click(function () {
			var uplist = $("#fileUpload");
			//alert(JSON.stringify(uplist));
			var sysCd = $("#sysCd").val();
			var opTypCd = $("#opTypCd").val();
			var verNo = $("#verNo").val();
			var data = {};
			if(StringUtils.isEmpty(sysCd)){
				alert("请先选择系统");
				return;
			}
			if(StringUtils.isEmpty(opTypCd)){
				alert("请先选择手机类型");
				return;
			}
			if(StringUtils.isEmpty(verNo)){
				alert("请先填写显示版本号");
				return;
			}
			data.sysCd = sysCd;
			data.opTypCd = opTypCd;
			data.verNo = verNo;
			var arrId = [];
			var fileNames = [];//用于判断是否有重名文件
			if(uplist.length < 1){
				alert("请先选择文件");
				return;
			}
			for (var i = 0; i < uplist.length; i++) {
				if (uplist[i].value) {
					arrId[i] = uplist[i].id;
					if ($.inArray(uplist[i].value, fileNames) >= 0) {
						$.ligerDialog.SQalert({content: uplist[i].value + "文件重名！", SQ_type: "warning"});
						return;
					}
					fileNames[i] = uplist[i].value;
				}
			}
			var wait_dialog = $.ligerDialog.SQalert({content: '上传中,请稍后...', SQ_type: "waitting"});
			$.ajaxFileUpload({
				url: '<%=path%>/upgrade/sysAppVerCfg/upload.do',
				secureuri: false,
				fileElementId: arrId,  //这里不在是以前的id了，要写成数组的形式！
				dataType: 'json',
				data: data,
				success: function (msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
						//alert(msg.data);
						uploadCallback(msg.data);
					} else {
						top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
					}
				},
				complete: function () {

				}
			});
		});
	});
</script>
</html>